*** main tables

clear all
set more off
set maxvar 20000

** note: type your directory here
global dir_dest "/replication/Data/"
global dir_dest_figures "/replication/Figures/"
global dir_dest_tables "/replication/Tables/" 



***********************************************************************************************************
// Table 1. Effects of changes in tariffs on exports on changes in regulation scores, 2001–2007
***********************************************************************************************************

// Table 1 Panel A. Main results, hand coding

set more off
use ${dir_dest}2_main_regression.dta,clear

// column 1 
keep if year==2001
sum pntr_us DT

reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc_st if year==2001 , cluster(provgb)
est store col1
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_m_wage tf_imp_wage lhc_st)
local p1=round(`e(p)',0.001)
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_m_wage tf_imp_wage lhc_st)
local p0=round(`e(p)',0.001)
sum d_lhc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col1] using ${dir_dest_tables}main_hc.tex,replace dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 2
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre if year==2001 , cluster(provgb)
est store col2
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre)
local p1=round(`e(p)',0.001)
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre)
local p0=round(`e(p)',0.001)
sum d_lhc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col2] using ${dir_dest_tables}main_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label

// column 3
keep if lambda13<=.0548622
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc_st if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col3
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_m_wage tf_imp_wage lhc_st)
local p1=round(`e(p)',0.001)
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_m_wage tf_imp_wage lhc_st)
local p0=round(`e(p)',0.001)
sum d_lhc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col3] using ${dir_dest_tables}main_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 4
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col4
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre)
local p1=round(`e(p)',0.001)
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre)
local p0=round(`e(p)',0.001)
sum d_lhc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col4] using ${dir_dest_tables}main_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 5
keep if d_l_gdppct!=.
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc_st if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
est store col5
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_m_wage tf_imp_wage lhc_st)
local p1=round(`e(p)',0.001)
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_m_wage tf_imp_wage lhc_st)
local p0=round(`e(p)',0.001)
sum d_lhc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col5] using ${dir_dest_tables}main_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 6
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col6
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist( tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre)
local p1=round(`e(p)',0.001)
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist( tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre)
local p0=round(`e(p)',0.001)
sum d_lhc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col6] using ${dir_dest_tables}main_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label
// column 7
keep if wage_lag!=. & gdppct_lag!=.
reg d_lhc tf_exp_wage tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre wage_lag gdppct_lag if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col7
boottest tf_exp_wage,cluster(provgb) rep(1000) seed(9)
local pb=`r(p)'
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(1) control_varlist(tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre wage_lag gdppct_lag)
local p1=round(`e(p)',0.001)
reg_ss d_lhc, shiftshare_var(tf_exp_wage) share_varlist(beta39 beta38 beta37 beta36 beta35 beta32 beta31 beta300 beta30 beta29 beta28 beta27 beta26 beta25 beta24 beta23 beta22 beta21 beta20 beta14 beta13 beta12 ) akmtype(0) control_varlist(tf_imp_wage tf_m_wage lhc_st pntr_us DT exp_pre imp_pre m_pre wage_lag gdppct_lag)
local p0=round(`e(p)',0.001)
sum d_lhc
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col7] using ${dir_dest_tables}main_hc.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx', Bootstrap, `pb', AKM1, `p1', AKM0, `p0') label


// Table 1 Panel B. Main results, random forest coding

set more off
use ${dir_dest}2_main_regression.dta,clear

// column 1 
keep if year==2001
reg d_lrf tf_exp_wage tf_imp_wage tf_m_wage lrf_st if year==2001 , cluster(provgb)
est store col1
sum d_lrf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col1] using ${dir_dest_tables}main_rf.tex,replace dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx') label
// column 2
reg d_lrf tf_exp_wage tf_imp_wage tf_m_wage lrf_st pntr_us DT exp_pre imp_pre m_pre if year==2001 , cluster(provgb)
est store col2
sum d_lrf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col2] using ${dir_dest_tables}main_rf.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx') label

// column 3
keep if lambda13<=.0548622
reg d_lrf tf_exp_wage tf_imp_wage tf_m_wage lrf_st if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col3
sum d_lrf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col3] using ${dir_dest_tables}main_rf.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx') label
// column 4
reg d_lrf tf_exp_wage tf_imp_wage tf_m_wage lrf_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col4
sum d_lrf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col4] using ${dir_dest_tables}main_rf.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx') label
// column 5
keep if d_l_gdppct!=.
reg d_lrf tf_exp_wage tf_imp_wage tf_m_wage lrf_st if year==2001 & lambda13<=.0548622 & d_l_gdppct!=., cluster(provgb)
est store col5
sum d_lrf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col5] using ${dir_dest_tables}main_rf.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx') label
// column 6
reg d_lrf tf_exp_wage tf_imp_wage tf_m_wage lrf_st pntr_us DT exp_pre imp_pre m_pre if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col6
sum d_lrf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col6] using ${dir_dest_tables}main_rf.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx') label
// column 7
keep if wage_lag!=. & gdppct_lag!=.
reg d_lrf tf_exp_wage tf_imp_wage tf_m_wage lrf_st pntr_us DT exp_pre imp_pre m_pre wage_lag gdppct_lag if year==2001 & lambda13<=.0548622, cluster(provgb)
est store col7
sum d_lrf
local my=round(`r(mean)', 0.01) 
local sdy=round(`r(sd)', 0.01)
sum tf_exp_wage
local mx=round(`r(mean)' ,0.01)
local sdx=round(`r(sd)',0.01)
outreg2 [col7] using ${dir_dest_tables}main_rf.tex,append dec(2) addtext(Mean y, `my', Sd y, `sdy', Mean x, `mx', Sd x, `sdx') label

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
drop if tf_m_wage==.
xtile pct=-tf_exp_wage, n(3)
bysort pct: sum tf_exp_wage

***********************************************************************************************************
// Table 2. Heterogeneous effects of changes in tariffs on exports on changes in regulations (2001–2007)
***********************************************************************************************************
set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
drop if d_l_gdppct==.

set more off
reg d_lhc c.tf_exp_wage##c.m_intensity tf_imp_wage tf_m_wage lhc_st  if year==2001, cluster(provgb)
sum m_intensity
local mi=round(`r(mean)', 0.01) 
local sdi=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_ht.tex,replace dec(2)  addtext(Mean I, `mi', Sd I, `sdi')
reg d_lhc c.tf_exp_wage##c.m_intensity tf_imp_wage tf_m_wage lhc_st exp_pre imp_pre m_pre pntr_us DT_share wage_lag gdppct_lag  if year==2001, cluster(provgb)
sum m_intensity if gdppct_lag!=.
outreg2 using ${dir_dest_tables}main_ht.tex,append  dec(2)  addtext(Mean I, `mi', Sd I, `sdi')
reg d_lhc c.tf_exp_wage##c.pvt_share tf_imp_wage tf_m_wage lhc_st if year==2001, cluster(provgb)
sum pvt_share
local mi=round(`r(mean)', 0.01) 
local sdi=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_ht.tex,append dec(2)  addtext(Mean I, `mi', Sd I, `sdi')
reg d_lhc c.tf_exp_wage##c.pvt_share tf_imp_wage tf_m_wage lhc_st exp_pre imp_pre m_pre pntr_us DT_share wage_lag gdppct_lag if year==2001, cluster(provgb)
sum pvt_share if gdppct_lag!=.
local mi=round(`r(mean)', 0.01) 
local sdi=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_ht.tex,append dec(2)  addtext(Mean I, `mi', Sd I, `sdi')
reg d_lhc c.tf_exp_wage##c.l_gdppct_st tf_imp_wage tf_m_wage lhc_st  if year==2001, cluster(provgb)
sum l_gdppct_st
local mi=round(`r(mean)', 0.01) 
local sdi=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_ht.tex,append dec(2)  addtext(Mean I, `mi', Sd I, `sdi')
reg d_lhc c.tf_exp_wage##c.l_gdppct_st tf_imp_wage tf_m_wage lhc_st exp_pre imp_pre m_pre pntr_us DT_share wage_lag gdppct_lag  if year==2001, cluster(provgb)
sum l_gdppct_st if gdppct_lag!=.
local mi=round(`r(mean)', 0.01) 
local sdi=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_ht.tex,append dec(2)  addtext(Mean I, `mi', Sd I, `sdi')
reg d_lhc c.tf_exp_wage##c.l_wage_st tf_imp_wage tf_m_wage lhc_st  if year==2001, cluster(provgb)
sum l_wage_st
local mi=round(`r(mean)', 0.01) 
local sdi=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_ht.tex,append dec(2)  addtext(Mean I, `mi', Sd I, `sdi')
reg d_lhc c.tf_exp_wage##c.l_wage_st tf_imp_wage tf_m_wage lhc_st exp_pre imp_pre m_pre pntr_us DT_share wage_lag gdppct_lag  if year==2001, cluster(provgb)
sum l_wage_st if gdppct_lag!=.
local mi=round(`r(mean)', 0.01) 
local sdi=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_ht.tex,append dec(2)  addtext(Mean I, `mi', Sd I, `sdi')

***********************************************************************************************************
// Table 3. The relationship between regulation scores and migrant outcomes in 2005
***********************************************************************************************************

set more off
use ${dir_dest}3_cross_section_2005.dta,clear

*** Log ones, weighted
set more off
reg insu_unem_migr l_score_total_2005 insu_unem_local l_migrant_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
sum insu_unem_migr
local mm=round(`r(mean)', 0.01) 
local sdm=round(`r(sd)', 0.01)
sum insu_unem_local
local ml=round(`r(mean)', 0.01) 
local sdl=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_wellbeing.tex,replace dec(2)  addtext(Mean migrant, `mm', Sd migrant, `sdm', Mean local, `ml', Sd local, `sdl')
reg pension_migr l_score_total_2005 pension_local l_migrant_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
sum pension_migr
local mm=round(`r(mean)', 0.01) 
local sdm=round(`r(sd)', 0.01)
sum pension_local
local ml=round(`r(mean)', 0.01) 
local sdl=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_wellbeing.tex,append dec(2)  addtext(Mean migrant, `mm', Sd migrant, `sdm', Mean local, `ml', Sd local, `sdl')
reg medicare_migr l_score_total_2005 medicare_local l_migrant_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
sum medicare_migr
local mm=round(`r(mean)', 0.01) 
local sdm=round(`r(sd)', 0.01)
sum medicare_local
local ml=round(`r(mean)', 0.01) 
local sdl=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_wellbeing.tex,append dec(2)  addtext(Mean migrant, `mm', Sd migrant, `sdm', Mean local, `ml', Sd local, `sdl')
reg term_cont_migr l_score_total_2005 term_cont_local l_migrant_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
sum term_cont_migr
local mm=round(`r(mean)', 0.01) 
local sdm=round(`r(sd)', 0.01)
sum term_cont_local
local ml=round(`r(mean)', 0.01) 
local sdl=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_wellbeing.tex,append dec(2)  addtext(Mean migrant, `mm', Sd migrant, `sdm', Mean local, `ml', Sd local, `sdl')
reg income_migr l_score_total_2005 income_local l_migrant_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
sum income_migr
local mm=round(`r(mean)', 0.01) 
local sdm=round(`r(sd)', 0.01)
sum income_local
local ml=round(`r(mean)', 0.01) 
local sdl=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_wellbeing.tex,append dec(2)  addtext(Mean migrant, `mm', Sd migrant, `sdm', Mean local, `ml', Sd local, `sdl')
reg enrol_migr l_score_total_2005 enrol_local l_migrant_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
sum enrol_migr
local mm=round(`r(mean)', 0.01) 
local sdm=round(`r(sd)', 0.01)
sum enrol_local
local ml=round(`r(mean)', 0.01) 
local sdl=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_wellbeing.tex, append dec(2)  addtext(Mean migrant, `mm', Sd migrant, `sdm', Mean local, `ml', Sd local, `sdl')
reg l_migrant_kid l_score_total_2005 l_local_kid l_migrant_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
sum l_migrant_kid
local mm=round(`r(mean)', 0.01) 
local sdm=round(`r(sd)', 0.01)
sum l_local_kid
local ml=round(`r(mean)', 0.01) 
local sdl=round(`r(sd)', 0.01)
outreg2 using ${dir_dest_tables}main_wellbeing.tex, append dec(2)  addtext(Mean migrant, `mm', Sd migrant, `sdm', Mean local, `ml', Sd local, `sdl')

set more off
reg insu_unem_local l_score_total_2005 l_local_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
outreg2 using ${dir_dest_tables}main_wellbeing_b.tex,replace dec(3)
reg pension_local l_score_total_2005 l_local_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
outreg2 using ${dir_dest_tables}main_wellbeing_b.tex,append dec(3)
reg medicare_local l_score_total_2005 l_local_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
outreg2 using ${dir_dest_tables}main_wellbeing_b.tex,append dec(3)
reg term_cont_local l_score_total_2005 l_local_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
outreg2 using ${dir_dest_tables}main_wellbeing_b.tex,append dec(3)
reg income_local l_score_total_2005 l_local_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
outreg2 using ${dir_dest_tables}main_wellbeing_b.tex,append dec(3)
reg enrol_local l_score_total_2005 l_local_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
outreg2 using ${dir_dest_tables}main_wellbeing_b.tex, append dec(3)
reg l_local_kid l_score_total_2005 l_local_adult_pop l_gdppct_2005 [aw=totpop_2005],cluster(provgb)
outreg2 using ${dir_dest_tables}main_wellbeing_b.tex, append dec(3)


***********************************************************************************************************
// Table 4. The relationship between changes in tariffs on exports (2001–2007), regulation changes (2001–2007) and changes in migrant flows (2000-2010)
***********************************************************************************************************

set more off
use ${dir_dest}2_main_regression.dta,clear
keep if year==2001
keep if lambda13<=.0548622
keep if d_l_gdppct!=.

global trade_shock tf_exp_wage tf_imp_wage tf_m_wage
sum d_in_pct d_in_cnty d_in_city d_in_prov
browse if d_in_cnty==.
browse if d_in_city==.
browse if d_in_prov==.

set more off
reg d_in_pct $trade_shock in_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr1.tex,replace dec(2)
reg d_in_pct d_lhc in_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr1.tex,append dec(2) 
reg d_in_pct $trade_shock d_lhc in_pct_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr1.tex,append dec(2) 
reg d_in_cnty $trade_shock l_in_cnty_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr1.tex,append dec(2) 
reg d_in_cnty d_lhc l_in_cnty_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr1.tex,append dec(2) 
reg d_in_cnty $trade_shock d_lhc l_in_cnty_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr1.tex,append dec(2) 


set more off
reg d_in_city $trade_shock l_in_city_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr2.tex,replace dec(2)
reg d_in_city d_lhc l_in_city_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr2.tex,append dec(2) 
reg d_in_city $trade_shock d_lhc l_in_city_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr2.tex,append dec(2) 
reg d_in_prov $trade_shock l_in_prov_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr2.tex,append dec(2) 
reg d_in_prov d_lhc l_in_prov_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr2.tex,append dec(2) 
reg d_in_prov $trade_shock d_lhc l_in_prov_st l_totpop_st, cluster(provgb)
outreg2 using ${dir_dest_tables}main_migr2.tex,append dec(2) 
